﻿using Meiam.System.Interfaces;
using Meiam.System.Interfaces.IService;
using Meiam.System.Model.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Meiam.System.Hostd.Controllers.Gokin
{
    /// <summary>
    /// 字典定义
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BIWorkController : ControllerBase
    {
        public readonly IYieldSummaryService _YieldSummaryService;
        public readonly ICutPieceTotalNumService _CutPieceTotalNumService;
        public readonly IEquipmentDropBoxService _EquipmentDropBoxService;
        public readonly IProportionSummaryService _ProportionSummaryService;
        public readonly IDropboxIndexWorkShopService _DropboxIndexWorkShopService;
        public readonly IMachineConfirmationService _MachineConfirmationService;
        public readonly ICutPieceEfficiencySummaryService _CutPieceEfficiencySummaryService;

        public BIWorkController(IEquipmentDropBoxService equipmentDropBoxService, ICutPieceTotalNumService cutPieceTotalNumService , IYieldSummaryService yieldSummaryService, IProportionSummaryService proportionSummaryService, IDropboxIndexWorkShopService dropboxIndexWorkShopService,ICutPieceEfficiencySummaryService cutPieceEfficiencySummaryService,IMachineConfirmationService machineConfirmationService)
        {
            
            _YieldSummaryService = yieldSummaryService;
            _EquipmentDropBoxService = equipmentDropBoxService;
            _ProportionSummaryService = proportionSummaryService;
            _CutPieceTotalNumService = cutPieceTotalNumService;
            _MachineConfirmationService = machineConfirmationService;
            _DropboxIndexWorkShopService = dropboxIndexWorkShopService;
            _CutPieceEfficiencySummaryService = cutPieceEfficiencySummaryService;
        }

        /// <summary>
        /// 良率汇总
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetYieldSummary(string shift, string startTime,string endTime)
        {
            var data = _YieldSummaryService.GetYieldSummaryData(shift,startTime, endTime);

            var response = new { result = 0, data = data, type = "良率汇总",query=new { shift= shift, startTime= startTime,endTime= endTime } };
            return new JsonResult(response);
        }

        /// <summary>
        /// 机检确认报表(数量汇总)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetEquipmentDropBoxNumSummary()
        {
            string startTime = DateTime.Now.AddHours(-2).ToString("yyyy-MM-dd HH:mm:ss");
            string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            var data = _EquipmentDropBoxService.GetEquipmentDropBoxNumSummary();
            var response = new { result = 0, data = data, type = "机检确认报表(数量汇总)", query = new { shift = "", startTime = startTime, endTime = endTime } };
            return new JsonResult(response);
        }

        /// <summary>
        /// 机检确认报表(汇总占比)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetEquipmentDropBoxProportionSummary()
        {
            var data = _ProportionSummaryService.GetEquipmentDropBoxProportionSummary();
            var response = new { result = 0, data = data, type = "机检确认报表(汇总占比)" };
            return new JsonResult(response);
        }
        

        /// <summary>
        /// 落盒关键指标(一车间)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDropboxIndexWorkShopOne()
        {
            var data = _DropboxIndexWorkShopService.GetDropBoxIndexWorkshopOneData();
            var response = new { result = 0, data = data, type = "落盒关键指标(一车间)" };
            return new JsonResult(response);
        }

        /// <summary>
        /// 落盒关键指标(二车间)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDropboxIndexWorkShopTwo()
        {
            var data = _DropboxIndexWorkShopService.GetDropBoxIndexWorkshopTwoData();
            var response = new { result = 0, data = data, type = "落盒关键指标(二车间)" };
            return new JsonResult(response);
        }

        /// <summary>
        /// 落盒关键指标(二车间)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDropboxIndexWorkShopThree()
        {
            var data = _DropboxIndexWorkShopService.GetDropBoxIndexWorkshopThreeData();
            var response = new { result = 0, data = data, type = "落盒关键指标(三车间)" };
            return new JsonResult(response);
        }

        /// <summary>
        /// 落盒关键指标(一车间占比)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDropboxIndexWorkShopOneRate()
        {
            var data = _DropboxIndexWorkShopService.GetGetDropBoxIndexWorkshopOneRateData();
            var response = new { result = 0, data = data, type = "落盒关键指标(一车间占比)" };
            return new JsonResult(response);
        }

        /// <summary>
        /// 落盒关键指标(二车间占比)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDropboxIndexWorkShopTwoRate()
        {
            var data = _DropboxIndexWorkShopService.GetGetDropBoxIndexWorkshopTwoRateData();
            var response = new { result = 0, data = data, type = "落盒关键指标(二车间占比)" };
            return new JsonResult(response);
        }

        /// <summary>
        /// 落盒关键指标(三车间占比)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDropboxIndexWorkShopThreeRate()
        {
            var data = _DropboxIndexWorkShopService.GetGetDropBoxIndexWorkshopThreeRateData();
            var response = new { result = 0, data = data, type = "落盒关键指标(三车间占比)" };
            return new JsonResult(response);
        }

        /// <summary>
        /// 切片效率汇总报表-8H
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetCutPieceEfficiencySummary8h()
        {
            var data = _CutPieceEfficiencySummaryService.GetCutPieceEfficiencySummaryData8H();
            var response = new { result = 0, data = data, type = "切片效率汇总报表-8H" };
            return new JsonResult(response);
        }

        [HttpGet]
        public IActionResult GetCutPieceTotalNumData()
        {
            var data = _CutPieceTotalNumService.GetSummaryData12H();
            var response = new { result = 0, data = data, type = "切片刀数断线汇总报表-12H" };
            return new JsonResult(response);
        }

        [HttpGet]
        public IActionResult GetMachineConfirmationData()
        {
            var data = _MachineConfirmationService.GetMachineConfirmationWorkshopOneAreaA4H();
            var response = new { result = 0, data = data, type = "机检确认报表-4H" };
            return new JsonResult(response);
        }
    }
}
